function listen(listener) {
    if (typeof window.addEventListener != 'undefined') {
        window.addEventListener('load', listener, false);
    } else if (typeof document.addEventListener != 'undefined') {
        document.addEventListener('load', listener, false);
    } else if (typeof window.attachEvent != 'undefined') {
        window.attachEvent('onload', listener);
    } else {
        var listener0 = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = listener;
        } else {
            window.onload = function () {
                listener0();
                listener();
            };
        }
    }
}

var bszCaller = {
    fetch: function (url, callback) {
        var fn = 'BusuanziCallback_' + Math.floor(Math.random() * 1099511627776);
        window[fn] = this.evalCall(callback);
        url = url.replace('=BusuanziCallback', '=' + fn);

        scriptTag = document.createElement('SCRIPT');
        scriptTag.type = 'text/javascript';
        scriptTag.defer = true;
        scriptTag.src = url;
        document.getElementsByTagName('HEAD')[0].appendChild(scriptTag);
    },
    evalCall: function (callback) {
        return function (data) {
            listen(function () {
                try {
                    callback(data);
                    scriptTag.parentElement.removeChild(scriptTag);
                } catch (e) {
                    bszTag.hides();
                }
            });
        }
    }
}

bszCaller.fetch("//service.ibruce.info/busuanzi?jsonpCallback=BusuanziCallback", function (data) {
    bszTag.texts(data);
    bszTag.shows();
});

var bszTag = {
    bszs: ['site_pv', 'page_pv', 'site_uv'],
    texts: function (json) {
        this.bszs.map(function (bsz) {
            var bv = document.getElementById('busuanzi_value_' + bsz);
            if (bv) bv.innerHTML = json[bsz];
        });
    },
    hides: function () {
        this.bszs.map(function (bsz) {
            var bc = document.getElementById('busuanzi_container_' + bsz);
            if (bc) bc.style.display = 'none';
        });
    },
    shows: function () {
        this.bszs.map(function (bsz) {
            var bc = document.getElementById('busuanzi_container_' + bsz);
            if (bc) bc.style.display = 'inline';
        });
    }
}